package com.macro.mall.portal.initialize;
import com.macro.mall.mapper.PmsProductCommentLabelMapper;
import com.macro.mall.model.SmsFlashPromotionSkuRelation;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ProductServicePreheat {
    @Autowired
    public StringRedisTemplate redisTemplate;
    @Autowired
    private PmsProductCommentLabelMapper labelMapper;
    @Scheduled(cron = "0 0 0 * * *")
    public void productServicePreheat(){
     List<SmsFlashPromotionSkuRelation> list=labelMapper.getAll();
        for (SmsFlashPromotionSkuRelation skuRelation : list) {
            redisTemplate.opsForValue().set("SMS_FLASH_PROMOTION_SKU_RELATION:"+skuRelation.getId(),skuRelation.getStock().toString());
        }
    }
    @PostConstruct
    public void init(){
        productServicePreheat();
    }
}
